package com.yidu.drug.action;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.drug.action.vo.InvoiceVo;
import com.yidu.drug.common.Message;
import com.yidu.drug.model.InvoiceModel;
import com.yidu.drug.service.InvoiceService;

@Controller
@RequestMapping("/Invoice")
public class InvoiceAction {
	@Resource
	private InvoiceService InvoiceService;
	Message msg = new Message();
	
	/**
	 * 根据ID查询
	 * @param roleId
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("findId")
	@ResponseBody
	public InvoiceVo findId(String invoiceId) throws IOException {
		System.out.println("进入根据ID查询方法,ID="+invoiceId +"===============");
		InvoiceVo commentVo=InvoiceService.findById(invoiceId);
		return commentVo;
	}
	
	/**
	 * 增加页面
	 * @param vo
	 */
	@RequestMapping("saveOrUpdate")
	@ResponseBody
	public void saveOrUpdate(InvoiceVo vo) {
		System.out.println("进来了增加页面方法============================");
		Timestamp time = new Timestamp(new Date().getTime());
		System.out.println(time);
		vo.setInvoiceDate(time);
		InvoiceService.saveOrUpdate(vo);
	}
	/**
	 * 增加
	 * @param session
	 * @param foodId
	 * @param commentContent
	 * @return
	 */
	@RequestMapping("add")
	@ResponseBody
	public Message add(HttpSession session, String foodId,String commentContent) {
		System.out.println("进入增加方法====================");
		InvoiceVo vo = new InvoiceVo();
		Timestamp time = new Timestamp(new Date().getTime());
		System.out.println(time);

		int add = InvoiceService.add(vo);
		if(add>0){
			msg.setMsg("成功");
			msg.setNum(1);
			return msg;
		}else{
			msg.setMsg("失败");
			msg.setNum(0);
			return msg;
		}
	}
	
	
	/**
	 * 查询所有
	 * @return
	 */
	@RequestMapping("findAlls")
	@ResponseBody
	public List<InvoiceModel> findAlls(){
		return InvoiceService.findAlls();
	}
	
	
	/**
	 *删除的方法 
	 */
	@RequestMapping("CommentDelete")
	@ResponseBody
	public Message manDelete(String id){
		System.out.println("进入用户删除的方法"+id+"===================");
		InvoiceService.delete(id);
		msg.setMsg("ok");
		return msg;
	}
}